//package com.springcloud;
//
//import feign.Feign;
//import okhttp3.ConnectionPool;
//import okhttp3.OkHttpClient;
//import org.springframework.boot.autoconfigure.AutoConfigureBefore;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.cloud.client.loadbalancer.LoadBalanced;
//import org.springframework.cloud.openfeign.FeignAutoConfiguration;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
//import org.springframework.web.client.RestTemplate;
//
//import java.util.concurrent.TimeUnit;
//
///**
// * 定制化HttpClient底层实现工具-OkHttp3 ，加载FeignAutoConfiguration类之前完成，以确保Feign客户端使用当前类中配置的OkHttp
// *
// * @author guotengteng
// */
//@Configuration
//@ConditionalOnClass(Feign.class)
//@AutoConfigureBefore(FeignAutoConfiguration.class)
//public class HttpClientConfiguration {
//
//    @Bean
//    public OkHttpClient okHttpClient() {
//        return new OkHttpClient.Builder()
//                //设置连接超时 视各业务自身情况而定
//                .connectTimeout(4, TimeUnit.SECONDS)
//                //设置读超时 视各业务自身情况而定
//                .readTimeout(4, TimeUnit.SECONDS)
//                //设置写超时 视各业务自身情况而定
//                .writeTimeout(4, TimeUnit.SECONDS)
//                //是否自动重连 必须设置为true -- 设置为false时，上游服务会自动关闭链接，下游使用已关闭的链接请求时，请求失败
//                .retryOnConnectionFailure(true)
//                //设置连接池 视各业务自身情况而定
//                .connectionPool(new ConnectionPool(50, 5L, TimeUnit.MINUTES))
//                .build();
//    }
//
//    @Bean
//    @LoadBalanced
//    public RestTemplate restTemplate() {
//        RestTemplate restTemplate = new RestTemplate();
//        OkHttpClient okHttpClient = okHttpClient();
//        restTemplate.setRequestFactory(new OkHttp3ClientHttpRequestFactory(okHttpClient));
//        return restTemplate;
//    }
//}
